﻿using Autofac;
using StarsAdmin.Core.DI;
using StarsAdmin.Core.Helpers;
using System.Reflection;
using Module = Autofac.Module;

namespace StarsAdmin.Web.Core.Modules
{
    public class RegisterModule : Module
    {
        public RegisterModule()
        {
        }

        protected override void Load(ContainerBuilder builder)
        {
            string[] assemblieList = ["StarsAdmin.Application", "StarsAdmin.Repository"];
            // 获得要注入的程序集
            Assembly[] assemblies = AssemblyHelper.GetAssemblyList(assemblieList);
            builder.RegisterAssemblyTypes(assemblies)
            .Where(type => !type.IsAbstract && typeof(IDependency).IsAssignableFrom(type))
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope()
            .PropertiesAutowired();

            base.Load(builder);
        }
    }
}